import { post, get } from '@/utils/request'
import type { 
  LoginRequest, 
  LoginResponse, 
  RegisterRequest, 
  RefreshTokenRequest, 
  RefreshTokenResponse 
} from '@/types/api'

// 认证相关API
export const authApi = {
  // 用户登录
  login: (data: LoginRequest): Promise<LoginResponse> => {
    return post<LoginResponse>('/auth/login', data)
  },

  // 用户注册
  register: (data: RegisterRequest): Promise<LoginResponse> => {
    return post<LoginResponse>('/auth/register', data)
  },

  // 刷新token
  refreshToken: (data: RefreshTokenRequest): Promise<RefreshTokenResponse> => {
    return post<RefreshTokenResponse>('/auth/refresh', data)
  },

  // 退出登录
  logout: (): Promise<any> => {
    return post('/auth/logout')
  },

  // 获取当前用户信息
  getCurrentUser: (): Promise<any> => {
    return get('/auth/me')
  },

  // 修改密码
  changePassword: (data: { oldPassword: string; newPassword: string }): Promise<any> => {
    return post('/auth/change-password', data)
  },

  // 忘记密码
  forgotPassword: (data: { email: string }): Promise<any> => {
    return post('/auth/forgot-password', data)
  },

  // 重置密码
  resetPassword: (data: { token: string; newPassword: string }): Promise<any> => {
    return post('/auth/reset-password', data)
  },

  // 验证邮箱
  verifyEmail: (data: { token: string }): Promise<any> => {
    return post('/auth/verify-email', data)
  },

  // 发送验证码
  sendVerificationCode: (data: { email: string; type: 'email' | 'phone' }): Promise<any> => {
    return post('/auth/send-code', data)
  }
}
